#!/usr/bin/env python

# This script joins sequentially the constraintForce.dat obtained
# from consecutive sets for a particular z-distance.

# usage: python joinConstraintForceFiles.py {z-constraint distance, eg., 01}
# example: python joinConstraintForceFiles.py 01

import sys, math

try:
    zDist = sys.argv[1];  
except:
    print "Usage:",sys.argv[0], "zDist directory (e.g., 01)"; sys.exit(1)


#define dt 20*10**(-6) 

dt = 20*10**(-6) # MD time-step in ns
stepCount = 1;
nameFile1 = 'analysisSet1/' + sys.argv[1] + '/constraintForce.dat'
nameFile2 = 'analysisSet2/' + sys.argv[1] + '/constraintForce.dat'
nameFile3 = 'analysisSet3/' + sys.argv[1] + '/constraintForce.dat'
nameFile4 = 'analysisSet4/' + sys.argv[1] + '/constraintForce.dat'
nameFile5 = 'analysisSet5/' + sys.argv[1] + '/constraintForce.dat'
nameFile6 = 'analysisSet6/' + sys.argv[1] + '/constraintForce.dat'
nameFile7 = 'analysisSet7/' + sys.argv[1] + '/constraintForce.dat'
nameFile8 = 'analysisSet8/' + sys.argv[1] + '/constraintForce.dat'

f1 = open( nameFile1, 'r')
f2 = open( nameFile2, 'r')
f3 = open( nameFile3, 'r')
f4 = open( nameFile4, 'r')
f5 = open( nameFile5, 'r')
f6 = open( nameFile6, 'r')
f7 = open( nameFile7, 'r')
f8 = open( nameFile8, 'r')

oFileName = sys.argv[1] + '-constraintForce_8sets.dat'
ofile = open( oFileName, 'w')

def printout(fileLine):
    global stepCount
    force = fileLine.split()
    time_ns = stepCount * dt
    ofile.write('%12.5f %12.3f\n' % (time_ns, float(force[0])))
    stepCount=stepCount+1

for line in f1: printout(line)
for line in f2: printout(line)
for line in f3: printout(line)
for line in f4: printout(line)
for line in f5: printout(line)
for line in f6: printout(line)
for line in f7: printout(line)
for line in f8: printout(line)
